<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    /**
     * 
     * Clean GET Array
     * 
     */
    class MyHook {

        public function __construct() {
            //$this->CI = & get_instance ();
            log_message('debug', 'MY_hook Initialized');
        }

        public function doHook() {
            // home form
            if (isset($_GET['dest_hot']) && $_GET['dest_hot'] == '-1')
                $_GET['dest_hot'] = "";

            //price calculation
            if (!isset($_GET['ages']))
                $_GET['ages'] = array();

            if (isset($_GET['nr_teenagers']) && $_GET['nr_teenagers'] != '0'):
                $this->setAges(13, $_GET['nr_teenagers']);
            endif;


            if (isset($_GET['nr_childrens']) && $_GET['nr_childrens'] != '0'):
                $this->setAges(5, $_GET['nr_childrens']);
            endif;

            if (isset($_GET['nr_babies']) && $_GET['nr_babies'] != '0'):
                $this->setAges(1, $_GET['nr_babies']);
            endif;

            /* Unset empty string ages */
            if (isset($_GET['ages'])):

                $cnt = count($_GET['ages']);
                for ($index = 0; $index < $cnt; $index++)
                    if ($_GET['ages'][$index] === "")
                        unset($_GET['ages'][$index]);

            endif;


            /* Unset ages if not any */
            if (empty($_GET['ages']))
                unset($_GET['ages']);

            if (isset(get_instance()->activeLang))
                $_GET['lang'] = get_instance()->activeLang;

            log_message('debug', 'MY_hook, method do_hook');
        }

        private function setAges($age, $count) {

            for ($i = 0; $i < $count; $i++)
                array_push($_GET['ages'], $age);
        }

    }

?>